package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.OrrMaterialCalibrationDetailMapper;
import com.yunhai.device.service.OrrMaterialCalibrationDetailService;
import com.yunhai.model.entity.orr.OrrMaterialCalibrationDetailEntity;
import com.yunhai.model.vo.orr.OrrMaterialCalibrationDetailQuery;
import com.yunhai.model.vo.orr.OrrMaterialCalibrationDetailVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrrMaterialCalibrationDetailServiceImpl implements OrrMaterialCalibrationDetailService {

    @Resource
    private OrrMaterialCalibrationDetailMapper orrMaterialCalibrationDetailMapper;

    /**
     * 获取 OrrMaterialCalibrationDetail 分页列表
     */
    @Transactional
    public IPage getOrrMaterialCalibrationDetailPagination(PaginationVo paginationVo, OrrMaterialCalibrationDetailQuery orrMaterialCalibrationDetailQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<OrrMaterialCalibrationDetailEntity> lqs = new LambdaQueryWrapper();
        orrMaterialCalibrationDetailMapper.selectPage(page, lqs);

        List<OrrMaterialCalibrationDetailEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return page;
    }


    /**
     * 获取 OrrMaterialCalibrationDetail 所有数据
     *
     */
    @Transactional
    public List<OrrMaterialCalibrationDetailEntity> getOrrMaterialCalibrationDetailAllList( OrrMaterialCalibrationDetailQuery orrMaterialCalibrationDetailQuery ) throws Exception {

        LambdaQueryWrapper<OrrMaterialCalibrationDetailEntity> lqs = new LambdaQueryWrapper();
        List<OrrMaterialCalibrationDetailEntity> list = orrMaterialCalibrationDetailMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 OrrMaterialCalibrationDetail 详情
     */
    @Transactional
    public OrrMaterialCalibrationDetailEntity getOrrMaterialCalibrationDetailDetail( Long id) throws Exception {

        OrrMaterialCalibrationDetailEntity orrMaterialCalibrationDetailEntity = orrMaterialCalibrationDetailMapper.selectById(id);
        return orrMaterialCalibrationDetailEntity;
    }


    /**
     * 新增 OrrMaterialCalibrationDetail
     * */
    @Transactional
    public void addOrrMaterialCalibrationDetail(OrrMaterialCalibrationDetailVo orrMaterialCalibrationDetailVo) throws Exception {

        OrrMaterialCalibrationDetailEntity orrMaterialCalibrationDetailEntity = new OrrMaterialCalibrationDetailEntity();
        ReflectionCopy.copyProperties( orrMaterialCalibrationDetailEntity, orrMaterialCalibrationDetailVo );
        orrMaterialCalibrationDetailMapper.insert(orrMaterialCalibrationDetailEntity);
        return;
    }


    /**
     * 更新 OrrMaterialCalibrationDetail
     * */
    @Transactional
    public void updateOrrMaterialCalibrationDetail( OrrMaterialCalibrationDetailVo orrMaterialCalibrationDetailVo) throws Exception {

        if( orrMaterialCalibrationDetailVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        OrrMaterialCalibrationDetailEntity orrMaterialCalibrationDetailEntity = new OrrMaterialCalibrationDetailEntity();
        ReflectionCopy.copyProperties( orrMaterialCalibrationDetailEntity, orrMaterialCalibrationDetailVo );
        orrMaterialCalibrationDetailMapper.updateById(orrMaterialCalibrationDetailEntity);
        return;
    }

    /**
     * 删除 OrrMaterialCalibrationDetail
     * */
    @Transactional
    public void batchRemoveOrrMaterialCalibrationDetail( List<Long> ids ) throws Exception {

        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        orrMaterialCalibrationDetailMapper.deleteBatchIds(ids);
    }

}